package cn.tedu.view;

import java.

import java.util.Scanner;

public class StudentView {
    private final Scanner SCANNER = new Scanner(System.in);

    public void mainview() {
        boolean isflag = true;
        while (isflag) {

            System.out.println("1.登陆");
            System.out.println("2.注册");
            System.out.println("3.退出");
            System.out.println("请输入");

            String a = SCANNER.next();
            if (a .equals("3")) {
                isflag=false;
                break;
            }
            switch (a) {
                case "1":
                    denglu();
                    break;
                case "2":
                    add();
                    break;
                default:
                    System.out.println("输入数据非法");
            }
        }
    }

    /*登陆*/
    private void denglu() {

        System.out.println("请输入姓名");
        String name = SCANNER.next();
        System.out.println("请输入账号");
        String zh = SCANNER.next();
        System.out.println("请输入密码");
        String password = SCANNER.next();
        System.out.println(DBStudent.yanzheng(name, zh, password));
        if (DBStudent.yanzheng(name, zh, password)) {
        denglumain( name);
        }

    }

    public void denglumain(String name) {
        boolean isflag=true;
        while (isflag){
            System.out.println("***********欢迎进入考试系统************");
            System.out.println("1.查看个人信息");
            System.out.println("2.修改个人信息");
            System.out.println("3.开始考试");
            System.out.println("5.           ");
            System.out.println("4.退出");

            String next1 = SCANNER.next();
            if (next1.equals("4")){
                isflag=false;
                break;
            }
            switch (next1) {
                case "1":

                    DBStudent.inputStudent(name);
                    break;
                case "2":
                    DBStudent.changStudent(name);
                    break;
                case "3":
                    DBStudent.duqu( name);
                    DBStudent.getscore(name);
                    break;
                default:
                    System.out.println("输入数据非法");
            }
        }
    }

    /*注册*/

    private void add() {
        System.out.println("**************欢迎注册********************");
        System.out.println("请输入学号");
        String id = SCANNER.next();
        System.out.println("请输入姓名");
        String name = SCANNER.next();
        System.out.println("请输入年龄");
        int age = SCANNER.nextInt();
        System.out.println("请输入班级");
        String clazz = SCANNER.next();
        System.out.println("请输入账号");
        String zh = SCANNER.next();
        System.out.println("请输入密码");
        String password = SCANNER.next();
        Student student = new Student(id, name, age, clazz, zh, password);
        DBStudent.saveStudent(student, "G:\\Project01\\Student\\" + name + ".txt");
        System.out.println("完成注册，您的基本信息为" + student);
        DBStudent.savepassword(name, zh, password);
        System.out.println("密码保存成功");
        mainview();
    }
}
